<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <form>
        <input type="text" id="username" name="username">
        <input type="text" id="age" name="age">
        <button type="button" id="btn">post提交</button>
    </form>

    <script src="jquery-2.1.1.min.js"></script>
    <script>
        $('#btn').click(function(){
            
            var data = {
                username: $('#username').val(),
                age: $('#age').val()
            }
            
            $.ajaxSetup({
                contentType: 'application/json;charset=UTF-8'
            })

            $.ajax({
                url:'http://localhost:8888/api/demo04-jquery-ajax-json-post',
                type: 'POST',
                data: JSON.stringify(data),//讲对象转换为json字符串
                //contentType: 'application/json;charset=UTF-8',
                success: function(result){
                    $("div").html(result)
                }})
            })
    </script>
</body>
</html>